<template>
  <el-affix :offset="0">
    <div style="height: 50px; line-height: 50px; border-bottom: 1px solid #ccc; display: flex;background-color: white">
      <div style="width: 200px; padding-left: 30px; font-weight: bold;color: dodgerblue">OnlineJudge</div>
      <div style="flex: 1"></div>
      <div style="width: 80px;">
        <el-dropdown style="align-self: center">
        <span class="el-dropdown-link">
         <p>{{ user.nickName }}</p> <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="$router.push('/person')">个人信息</el-dropdown-item>
              <el-dropdown-item @click="logout">退出系统</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </el-affix>

</template>

<script>
import request from "@/utils/request";

export default {
  name: "Header",
  //props: ['user'],
  data() {
    return {
      user: {}
    }
  },
  created() {
    let userStr = sessionStorage.getItem("user") || "{}"
    this.user = JSON.parse(userStr)

  },
  methods: {
    logout() {
      request.get("/user/logout").then(res => {
        sessionStorage.clear();
        this.$router.push('/login');
      });
    }
  }
}
</script>

<style scoped>
p{
  margin-top: 14px;
  font-size: 20px;
}
</style>